<template>

  <div>

    <el-form  :model="form" label-width="80px">
      <el-form-item label="部门编号">
        <el-input v-model="form.deptno"></el-input>
      </el-form-item>

      <el-form-item label="部门名称">
        <el-input v-model="form.dname"></el-input>
      </el-form-item>

      <el-form-item label="办公地址">
        <el-input v-model="form.loc"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="save()">保存</el-button>

      </el-form-item>
    </el-form>



  </div>

</template>

<script>
import {getForm,save,update} from "@/api/table";
export default{
  name:'DeptEdid',
  props:["id"],
  data(){
    return {
      form:{
        deptno:'',
        dname:'',
        loc:''
      }
    }
  },
  created() {
    if(this.id){
      this.getForm();
    }
  },
  methods:{
    //修改的时候初始化使用
    getForm(){
      getForm(this.id).then((response) =>{
        this.form = response.data;
      }).catch((e)=>{
        console.log("失败的情况",e)
      });




    },
    save(){
      let promise  =  null;
      if(this.id) {
        promise = update( this.form);
      }else{
        promise = save( this.form);
      }
      // form /
      promise.then((response) =>{
        let {success} = response.data;
        if(success){
          this.$message.success("保存成功");

          //关掉自己
          this.$emit("update:visible",false);
          this.$emit("close");
        }
      }).catch((e)=>{
        console.log("失败的情况",e)
      });

    }
  }
}


</script>

<style scoped>




</style>
